﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace INF7GEN
{
    [Serializable()]
    public class ADVBookPage : ISerializable
    {
        private bool firstPage = false;//true if this page is the first
        private bool deadEnd = false;//true if this page is a dead end
        private bool linearMove = false;//if true then followingPage is the next page
        private int numCond = 0;//the number of <cond> in PageContent
        private String name = "";//internal reference
        private String defaultPageContent = "";//the default page text in game
        private String followingPage = "";//optional, represents a linear move to one page, this is the pages internal name.
        private List<ADVBookChoice> choices = new List<ADVBookChoice>();//the choices that this page has, or the pages you can jump to from here

        public ADVBookPage ()
        {

        }


        //--------------------------------------------------------------------
        //Serialization-------------------------------------------------------
        public ADVBookPage(SerializationInfo info, StreamingContext ctxt)
        {
            this.name = (String)info.GetValue("PAGEName", typeof(String));
            this.defaultPageContent = (String)info.GetValue("PAGEDefaultPageContent", typeof(String));
            this.followingPage = (String)info.GetValue("PAGEFollowingPage", typeof(String));
            this.numCond = (int)info.GetValue("PAGENumCond", typeof(int));
            this.deadEnd = (bool)info.GetValue("PAGEDeadEnd", typeof(bool));
            this.choices = (List<ADVBookChoice>)info.GetValue("PAGEChoices", typeof(List<ADVBookChoice>));
            this.linearMove = (bool)info.GetValue("PAGELinearMove", typeof(bool));
            this.firstPage = (bool)info.GetValue("PAGEFirstPage", typeof(bool));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("PAGEName", this.name);
            info.AddValue("PAGEDefaultPageContent", this.defaultPageContent);
            info.AddValue("PAGEFollowingPage", this.followingPage);
            info.AddValue("PAGENumCond", this.numCond);
            info.AddValue("PAGEDeadEnd", this.deadEnd);
            info.AddValue("PAGEChoices", this.choices);
            info.AddValue("PAGELinearMove", this.linearMove);
            info.AddValue("PAGEFirstPage", this.firstPage);
        }
        //-------------------------------------------------------------------



        public override string ToString()
        {
            string s = this.name;
            return "Page: " + s;
        }

        /// <summary>
        /// re_initializes choices.
        /// </summary>
        public void resetChoices()
        {
            this.choices = new List<ADVBookChoice>();
        }

        /// <summary>
        /// accessor method for choices list
        /// </summary>
        public List<ADVBookChoice> ListOfChoices
        {
            get { return choices; }
            set { choices = value; }
        }

        /// <summary>
        /// name used for referencing object in the game listing.
        /// </summary>
        public String InternalName
        {
            get { return name; }
            set { name = value; }
        }


        /// <summary>
        /// the number of cond in PageContent.
        /// </summary>
        public int NumCond
        {
            get { return numCond; }
            set { numCond = value; }
        }

        /// <summary>
        /// true if this page is a dead end.
        /// </summary>
        public bool DeadEnd
        {
            get { return deadEnd; }
            set { deadEnd = value; }
        }

        /// <summary>
        /// true if this page is the first.
        /// </summary>
        public bool FirstPage
        {
            get { return firstPage; }
            set { firstPage = value; }
        }

        /// <summary>
        /// true if this page jumps in a linear fashion to another page with no choices.
        /// If true then make sure to set FollowingPage to a page internal name.
        /// </summary>
        public bool LinearMove
        {
            get { return linearMove; }
            set { linearMove = value; }
        }


        /// <summary>
        /// default text printed every time page is loaded in game.
        /// </summary>
        public String DefaultPageContent
        {
            get { return defaultPageContent; }
            set { defaultPageContent = value; }
        }


        /// <summary>
        /// optional, represents a linear move to one page.
        /// </summary>
        public String FollowingPage
        {
            get { return followingPage; }
            set { followingPage = value; }
        }







    }
}
